<template>
  <div class="container top-0 position-sticky z-index-sticky">
    <div class="row">
      <div class="col-12"></div>
    </div>
  </div>
  <main class="mt-0 main-content main-content-bg">
    <section>
      <div class="page-header min-vh-75">
        <div class="container">
          <div class="row">
            <div class="mx-auto col-xl-4 col-lg-5 col-md-6 d-flex flex-column">
              <div class="mt-8 card card-plain">
                <div class="pb-0 card-header text-start">
                  <h3 class="font-weight-bolder text-success text-gradient">
                    欢迎使用东软智能云工厂
                  </h3>
                  <p class="mb-0">请输入您的账号密码...</p>
                </div>
                <div class="card-body">
                  <form role="form" class="text-start">
                    <label>账号</label>
                    <el-input v-model="account" placeholder="账号"></el-input>
                    <label>密码</label>
                    <el-input
                      id="password"
                      type="password"
                      placeholder="密码"
                      v-model="password"
                      style="margin-bottom: 20px"
                    ></el-input>

                    <vsud-switch id="rememberMe" name="rememberMe" checked>
                      记住我
                    </vsud-switch>
                    <p>我已阅读并接受云工厂用户协议和隐私政策</p>
                    <div class="text-center">
                      <vsud-button
                        class="my-4 mb-2"
                        variant="gradient"
                        color="success"
                        full-width
                        @click="login()"
                        >登录
                      </vsud-button>
                    </div>
                  </form>
                </div>
                <div class="px-1 pt-0 text-center card-footer px-lg-2">
                  <p class="mx-auto mb-4 text-sm">
                    没有账户？
                    <router-link
                      :to="{ name: 'Sign Up' }"
                      class="text-success text-gradient font-weight-bold"
                      >去注册</router-link
                    >
                  </p>
                </div>
              </div>
            </div>
            <div class="col-md-6">
              <div
                class="top-0 oblique position-absolute h-100 d-md-block d-none me-n8"
              >
                <div
                  class="bg-cover oblique-image position-absolute fixed-top ms-auto h-100 z-index-0 ms-n6"
                  :style="{
                    backgroundImage:
                      'url(' +
                      require('@/assets/img/curved-images/curved9.jpg') +
                      ')',
                  }"
                ></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </main>
</template>

<script>
import VsudSwitch from "@/components/VsudSwitch.vue";
import VsudButton from "@/components/VsudButton.vue";
const body = document.getElementsByTagName("body")[0];
import { mapMutations } from "vuex";
// import { faHelicopterSymbol } from '@fortawesome/free-solid-svg-icons';
import { ElMessage } from "element-plus";
export default {
  name: "SignIn",
  data() {
    return {
      account: "",
      password: "",
    };
  },
  components: {
    VsudSwitch,
    VsudButton,
  },
  created() {
    this.toggleEveryDisplay();
    this.toggleHideConfig();
    body.classList.remove("bg-gray-100");
  },
  beforeUnmount() {
    this.toggleEveryDisplay();
    this.toggleHideConfig();
    body.classList.add("bg-gray-100");
  },
  mounted() {
    document.addEventListener("keyup", this.handleEnterKey);
  },
  unmounted() {
    document.removeEventListener("keyup", this.handleEnterKey);
  },
  methods: {
    ...mapMutations(["toggleEveryDisplay", "toggleHideConfig"]),
    handleEnterKey(ev) {
      if (ev.key == "Enter") {
        this.login();
      }
    },
    login() {
      console.log("haha");
      localStorage.setItem("account", this.account);

      // if(this.password!="123123")
      // {
      //   ElMessageBox.alert("您的账号密码不匹配", "出错", {
      //   confirmButtonText: "OK",
      // });
      // }
      if (this.password === "" || this.account === "") {
        ElMessage({
          message: "账号或密码不能为空",
          type: "error",
        });
      } else if (this.password != "123123") {
        ElMessage({
          message: "您的账号密码不匹配",
          type: "error",
        });
      } else {
        this.$router.push({
          path: "/" + this.account,
          query: {
            character: this.account,
          },
        });
      }
    },
  },
};
</script>
